package com.lpgu;


import com.lpgu.config.SpringDataJpaConfig;
import com.lpgu.repositories.CustomerRepository;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;

import javax.persistence.EntityManager;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Proxy;
import java.lang.reflect.Type;

/**
 * @author: lpgu
 * @describe:MainStart2
 * @createAt: 2022/1/5 21:21
 * 注释掉注解 @EnableJpaRepositories(basePackages = "com.lpgu.repositories")
 * 扫描器的实现：把CustomerRepository接口交给spring管理
 * 1、spring自己的扫描器只能够扫描@componet、@Service等，不能给扫描接口
 * 2、自定义beandefinition继承ClassPathBeanDefinitionScanner，重写isCandidateComponent方法
 * 3、自定义扫描器JpaClassBeanDefinitionScanner继承ClassPathBeanDefinitionScanner
 * 4、接口不能给实例化，因此使用factorybean实例化bean
 */

public class MainStart2 {
    public static void main(String[] args) throws ClassNotFoundException {
        AnnotationConfigApplicationContext ioc = new AnnotationConfigApplicationContext(SpringDataJpaConfig.class);

        CustomerRepository customerRepository = ioc.getBean(CustomerRepository.class);

        customerRepository.findById(3L);
    }
}
